package baseFx.serialization.json.jackson;

import baseFx.common.utils.ConvertUtils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;

public class EnumDeserializer extends JsonDeserializer<Enum<?>> {
    private Class<Enum<?>> type;

    public EnumDeserializer(Class<Enum<?>> type) {
        this.type = type;
    }

    @Override
    public Enum<?> deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String value = jsonParser.getValueAsString();
        return ConvertUtils.change(value, type);
    }
}
